package cn.alex.sso.project.mapper;

import cn.alex.sso.project.entity.SysLoginLog;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;

/**
 * @author Alex
 * @description 针对表【sys_login_log(登录日志表)】的数据库操作Mapper
 * @createDate 2024-10-22 14:02:48
 * @Entity generator.entity.SysLoginLog
 */
public interface SysLoginLogMapper extends BaseMapper<SysLoginLog> {

    default LambdaQueryWrapper<SysLoginLog> getQueryWrapper(SysLoginLog loginLog) {
        return new LambdaQueryWrapper<SysLoginLog>()
                .eq(ObjUtil.isNotEmpty(loginLog.getUserId()), SysLoginLog::getUserId, loginLog.getUserId())
                .like(StrUtil.isNotBlank(loginLog.getUsername()), SysLoginLog::getUsername, loginLog.getUsername())
                .like(StrUtil.isNotBlank(loginLog.getNickName()), SysLoginLog::getUsername, loginLog.getUsername())
                .eq(ObjUtil.isNotEmpty(loginLog.getStatus()), SysLoginLog::getStatus, loginLog.getStatus())
                .between(ObjUtil.isNotEmpty(MapUtil.getStr(loginLog.getExtra(), "startLoginTime")) && ObjUtil.isNotEmpty(MapUtil.getStr(loginLog.getExtra(), "endLoginTime")),
                        SysLoginLog::getLoginTime,
                        MapUtil.getStr(loginLog.getExtra(), "startLoginTime"),
                        MapUtil.getStr(loginLog.getExtra(), "endLoginTime")
                )
                .orderByDesc(SysLoginLog::getLoginTime);
    }

    IPage<SysLoginLog> selectPage(Page<SysLoginLog> page, @Param("log") SysLoginLog loginLog);
}




